/**
 * 
 */
package edu.cmich.cps.cps240.partyprincesspalace.hw06;

import static org.junit.Assert.*;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.Vector;

import org.junit.Test;

/**
 * @author roric1je
 *
 */
public class ChipTest {

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#draw(java.awt.Graphics)}.
	 */
	@Test
	public void testDraw() {
		//Can't test this
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#move(java.awt.Point)}.
	 */
	@Test
	public void testMove() {
		Rectangle rec = new Rectangle(5, 5);
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(rec, ins, outs, null);
		rec = chip.getRectangle();
		Point spot = new Point(7, 7);
		chip.move(spot);
		Rectangle newRec = chip.getRectangle();
		int startX = rec.x;
		int startY = rec.y;
		int endX = newRec.x;
		int endY = newRec.y;
		startX = startX + 7;
		startY = startY + 7;
		assertEquals(startX, endX);
		assertEquals(startY, endY);
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#returnLocation()}.
	 */
	@Test
	public void testReturnLocation() {
		Rectangle rec = new Rectangle(5, 5);
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(rec, ins, outs, null);
		Point spot = chip.returnLocation();
		int startX = rec.x;
		int startY = rec.y;
		int endX = spot.x;
		int endY = spot.y;
		assertEquals(startX, endX);
		assertEquals(startY, endY);
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#remove()}.
	 */
	@Test
	public void testRemove() {
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(null, ins, outs, null);
		ChipPin in = new ChipPin("in", chip, null);
		ChipPin out = new ChipPin("out", chip, null);
		Wire wire = new Wire();
		ins.add(in);
		outs.add(out);
		
		wire.attachTo(in);
		wire.attachTo(out);
		
		assertNotNull(in.getPartner());
		assertNotNull(out.getPartner());
		
		chip.remove();
		
		assertNull(in.getPartner());
		assertNull(out.getPartner());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#isClose(java.awt.Point)}.
	 */
	@Test
	public void testIsClose() {
		Rectangle rec = new Rectangle(5, 5);
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(rec, ins, outs, null);
		assertTrue(chip.isClose(chip.returnLocation()));
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#setName(java.lang.String)}.
	 */
	@Test
	public void testSetName() {
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(null, ins, outs, null);
		assertNull(chip.getName());
		chip.setName("name");
		assertEquals("name", chip.getName());
		chip.setName("");
		assertEquals("name", chip.getName());
		chip.setName(null);
		assertEquals("name", chip.getName());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#getName()}.
	 */
	@Test
	public void testGetName() {
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(null, ins, outs, null);
		assertNull(chip.getName());
		chip.setName("name");
		assertEquals("name", chip.getName());
		chip.setName(null);
		assertEquals("name", chip.getName());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#Chip(java.awt.Rectangle, java.util.Vector, java.util.Vector, java.lang.String)}.
	 */
	@Test
	public void testChipRectangleVectorOfChipPinVectorOfChipPinString() {
		Rectangle rec = new Rectangle();
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(rec, ins, outs, "Name");
		assertEquals(rec, chip.getRectangle());
		assertEquals("Name", chip.getName());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#Chip(edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip)}.
	 */
	@Test
	public void testChipChip() {
		Rectangle rec = new Rectangle();
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(rec, ins, outs, "Name");
		Chip testChip = new Chip(chip);
		assertEquals(rec, testChip.getRectangle());
		assertEquals("Name", testChip.getName());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#isInputPin(edu.cmich.cps.cps240.partyprincesspalace.hw06.Pin)}.
	 */
	@Test
	public void testIsInputPin() {
		ChipPin inpin = new ChipPin(null, null, null);
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(null, ins, outs, null);
		assertFalse(chip.isInputPin(inpin));
		ins.add(inpin);
		assertTrue(chip.isInputPin(inpin));
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#isOutputPin(edu.cmich.cps.cps240.partyprincesspalace.hw06.Pin)}.
	 */
	@Test
	public void testIsOutputPin() {
		ChipPin outpin = new ChipPin(null, null, null);
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(null, ins, outs, null);
		assertFalse(chip.isOutputPin(outpin));
		outs.add(outpin);
		assertTrue(chip.isOutputPin(outpin));
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#getRectangle()}.
	 */
	@Test
	public void testGetRectangle() {
		Rectangle rec = new Rectangle();
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(rec, ins, outs, null);
		assertEquals(rec, chip.getRectangle());
	}

	/**
	 * Test method for {@link edu.cmich.cps.cps240.partyprincesspalace.hw06.Chip#getNearbyPin(java.awt.Point)}.
	 */
	@Test
	public void testGetNearbyPin() {
		Rectangle rec = new Rectangle(5, 5);
		ChipPin out = new ChipPin(null, null, null);
		ChipPin in = new ChipPin(null, null, null);
		Vector<ChipPin> ins = new Vector<ChipPin>();
		Vector<ChipPin> outs = new Vector<ChipPin>();
		Chip chip = new Chip(rec, ins, outs, null);
		Point inputLoc = new Point(4, 4);
		in.setLocation(inputLoc);
		Point outputLoc = new Point(11, 6);
		out.setLocation(outputLoc);
		Point inSpot = new Point(5, 5);
		Point outSpot = new Point(10, 5);
		assertNull(chip.getNearbyPin(inSpot));
		assertNull(chip.getNearbyPin(outSpot));
	}

}
